package com.atues.backtrack.subsets;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    List<List<Integer>> res = new ArrayList<>();
    List<Integer> path =  new ArrayList<>();
    public List<List<Integer>> subsets(int[] nums) {
        backtracking(nums,0);

        return res;

    }

    void backtracking(int[] nums , int start){
        res.add(new ArrayList<>(path));

        for(int i = start ; i < nums.length ; i++){
            path.add(nums[i]);
            backtracking(nums,i+1);
            path.remove(path.size() - 1);
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {1, 2, 3};
        List<List<Integer>> lists = solution.subsets(nums);
        System.out.println(JSON.toJSONString(lists));
    }
}
